<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <link rel="stylesheet" href="layui/style/admin.css" media="all">
    <link rel="stylesheet" href="layui/style/login.css" media="all">
</head>
<body>
<div class="layui-login-bg"></div>
<div class="layadmin-user-login layadmin-user-display-show "
     id="LAY-user-login"
     style="align-items: center; justify-content: center; ">

    <div class="layadmin-user-login-main login-form"  >
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>OA</h2>
        </div>
        <div
                class="layadmin-user-login-box layadmin-user-login-body layui-form ">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                       for="LAY-user-login-username"></label> <input type="text"
                                                                     name="username" id="LAY-user-login-username"
                                                                     lay-verify="required" placeholder="用户名"
                                                                     class="layui-input">
            </div>
            <div class="layui-form-item">
                <label
                        class="layadmin-user-login-icon layui-icon layui-icon-password"
                        for="LAY-user-login-password"></label> <input type="password"
                                                                      name="password" id="LAY-user-login-password"
                                                                      lay-verify="required"
                                                                      placeholder="密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-xs7">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
                               for="LAY-user-login-vercode"></label> <input type="text"
                                                                            name="veryCode" id="LAY-user-login-vercode"
                                                                            lay-verify="required" placeholder="图形验证码"
                                                                            class="layui-input">
                    </div>
                    <div class="layui-col-xs5">
                        <div style="margin-left: 10px;">
                            <img src="servlet/imageRandServlet"
                                 class="layadmin-user-login-codeimg" id="LAY-user-get-vercode"
                                 onclick="this.src='servlet/imageRandServlet?tm='+Math.random()">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item" style="margin-bottom: 20px;"></div>
            <div class="layui-form-item">
                <button type="button" class="layui-btn layui-btn-fluid" lay-submit
                        lay-filter="LAY-user-login-submit">登 入
                </button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="layui/layui.js"></script>
<script type="text/javascript" src="js/jquery1.9.1.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script>

    layui.use(['layer', 'form'], function (layer, form) {

        form.render();
        //提交
        form.on('submit(LAY-user-login-submit)', function (obj) {
            obj.field.password = Base64.encode(obj.field.password);
            //请求登入接口
            $.ajax({
                type: 'post',
                url: '../login/loginSystem',
                data: JSON.stringify(obj.field),
                headers: {
                    'Content-Type': 'application/json;charset=utf-8'
                },
                success: function (data) {
                    if (data.success) {
                        layer.msg(
                            '登入成功',
                            {
                                icon: 1,
                                time: 1000
                            },
                            function () {
                                //设置浏览器储存信息
                                setToken(Base64.encode(data.obj.toString()));

                                ////屏幕可用工作区宽
                                const clientWidth = window.screen.availWidth;
                                if (clientWidth>=992){
                                    // layer.msg('请通过手机渠道进行访问！', {icon: 2});
                                    //电脑后台主页
                                    location.href = 'main.html';
                                } else{
                                    //手机后台主页
                                    location.href = 'phone-main.html';
                                }

                            });
                    } else {

                        layer.msg('登入失败' + data.msg, {icon: 2});
                        changeVeryCode();
                        $('#LAY-user-get-vercode').trigger('click');
                    }

                },
                error: function (o) {
                    console.log(o);
                }
            });

        });

        //回车登录
        window.onkeydown = function (e) {
            if (e.keyCode === 13) {
                $('button[lay-submit]').trigger('click')
            }
        };

        // 刷新验证码
        function changeVeryCode() {
            var veryCode = document.getElementById('LAY-user-get-vercode');
            veryCode.src = 'servlet/imageRandServlet?' + Math.random();
        }
    });


</script>
</body>
</html>